package com.example.note.database;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

@Dao
public interface DiaryDao {
    
    @Insert
    long insertDiary(DiaryEntity diary);
    
    @Update
    void updateDiary(DiaryEntity diary);
    
    @Delete
    void deleteDiary(DiaryEntity diary);
    
    @Query("SELECT * FROM diary ORDER BY timestamp DESC")
    LiveData<List<DiaryEntity>> getAllDiaries();
    
    @Query("SELECT * FROM diary WHERE id = :id")
    LiveData<DiaryEntity> getDiaryById(int id);
    
    @Query("SELECT * FROM diary WHERE date = :date ORDER BY timestamp DESC")
    LiveData<List<DiaryEntity>> getDiariesByDate(String date);
    
    @Query("SELECT * FROM diary WHERE title LIKE '%' || :keyword || '%' OR content LIKE '%' || :keyword || '%' ORDER BY timestamp DESC")
    LiveData<List<DiaryEntity>> searchDiaries(String keyword);
    
    @Query("SELECT * FROM diary WHERE isHandwritten = 1 ORDER BY timestamp DESC")
    LiveData<List<DiaryEntity>> getHandwrittenDiaries();
    
    @Query("DELETE FROM diary WHERE id = :id")
    void deleteDiaryById(int id);
    
    @Query("SELECT COUNT(*) FROM diary")
    LiveData<Integer> getDiaryCount();
}